Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Improve error handling for Glances widgets #3657

Merged
merged 6 commits into from
Jun 23, 2024
Merged

Conversation

mjsully
Copy link
Contributor

@mjsully mjsully commented Jun 21, 2024

Proposed change

I have the Glances widgets deployed in my Homepage instance and noticed that when a host is unreachable the widgets do not handle the errors as the other widgets do. It results in an ugly error message which doesn't respect either the global or service-level hideErrors. Here is an example from my deployment:

glances-widget-bug

I have rewritten parts of the components such that the Error component is no longer needed, as it is now implemented within the Container component. The service and error attributes are now passed into the Container component, such that the service-level hideErrors flag can be checked. Additionally, the global settings are now imported into the Container component so the global hideErrors flag can be checked. Within each component, if the service data containers an "error" key, the widget will now display an error message in line with other widgets. See the screenshot below:

glances-widget-fix-showErrors

Additionally, see the below screenshot testing the service-level hideErrors flag set to true for one widget:

glances-widget-fix-hideErrors

Type of change

  • New service widget
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Documentation only
  • Other (please explain)

Checklist:

  • If applicable, I have added corresponding documentation changes.
  • If applicable, I have reviewed the feature and / or service widget guidelines.
  • I have checked that all code style checks pass using pre-commit hooks and linting checks.
  • If applicable, I have tested my code for new features & regressions on both mobile & desktop devices, using the latest version of major browsers.

Copy link
Collaborator

@shamoon shamoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can take a real look at this soon but my first thought is that the logic to respect errors should just be moved inside Error, instead of all the other changes for removing it. and in info and gpu where you check for the error property presumably that should become the error for the Error component

@mjsully
Copy link
Contributor Author

mjsully commented Jun 21, 2024

Hi,

I don't necessarily disagree, the only reason I wrote the code this way is because the Error component for the glances widget essentially just returns the div with the localised translation:

return <div className="absolute bottom-2 left-2 z-20 text-red-400 text-xs opacity-75">{t("widget.api_error")}</div>;

So it was just to tidy the imports and dependencies up a bit. By the way, I'm on UK timezone so if I don't reply quickly I'm probably asleep!

@shamoon
Copy link
Collaborator

shamoon commented Jun 21, 2024

Sure, but separating them logically makes sense and that's also how the rest of the app does it. Also would significantly reduce the diff here.

Let us know if youre OK making the change, I can also take care of it if thats better.

@mjsully
Copy link
Contributor Author

mjsully commented Jun 21, 2024

Sure, let me make the changes and commit.

@mjsully
Copy link
Contributor Author

mjsully commented Jun 22, 2024

I've now reintroduced the error component and import it within the container component. Following the implementation style in e.g. the Home Assistant widget

return <Container service={service} error={error} />;
the error handling is still done within the container component. Let me know if you want any other changes making.

@shamoon
Copy link
Collaborator

shamoon commented Jun 22, 2024

That wasnt exactly what I had in mind. Please take a look at the changes here. (also FYI https://eslint.org/docs/latest/rules/no-prototype-builtins )

and let me know if you have any thoughts or concerns

@shamoon shamoon enabled auto-merge (squash) June 22, 2024 14:19
@mjsully
Copy link
Contributor Author

mjsully commented Jun 22, 2024

Thanks for this, and thanks for the link that's good to know. As for the changes, it seems like there isn't a consistent implementation of the error handling (e.g. the Home Assistant ref I provided was similar to my own implementation but different to the one you have provided in the changes.) - either way the result will be the same and looks good to me.

@shamoon
Copy link
Collaborator

shamoon commented Jun 22, 2024

Point taken, I've gone back to a bit of a mix

@shamoon shamoon changed the title Fix: Improve error handling for Glances widgets when host is unreachable Fix: Improve error handling for Glances widgets Jun 22, 2024
Copy link
Collaborator

@shamoon shamoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thanks again

@shamoon shamoon merged commit f07d595 into gethomepage:main Jun 23, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants